import { createStore } from 'vuex'
import vuexP from 'vuex-persistedstate'
export default createStore({
  state: {
    gradesList:[],//学生成绩
  },
  getters: {
  },
  mutations: {
    add(state,obj){
        // obj就是form表单的数据
        // 计算综合成绩   技能*0.8+理论*0.2
        let total = Number(obj.skill*0.8) + Number(obj.theory*0.2)
        
        if(total>=90){
            // total 和status都是给obj新加的字段
            obj.total = total
            obj.status = 1

        }else if(total<90 && total>=80){
            obj.total = total
            obj.status = 2
        }else{
            obj.total = total
            obj.status = 3
        }
        // 添加
        state.gradesList.push(obj)


    },
    edit(state,obj){
        // 把index form从obj里面解构出来  obj里面的form才是form表单的数据
        let {index,form} = obj
        let total = Number(form.skill*0.8) + Number(form.theory*0.2)
        
        if(total>=90){
            // total 和status都是给obj新加的字段
            form.total = total
            form.status = 1

        }else if(total<90 && total>=80){
            form.total = total
            form.status = 2
        }else{
            form.total = total
            form.status = 3
        }
        // 编辑
        state.gradesList[index]=form

    }
    

  },
  actions: {
  },
  modules: {
  },
  plugins:[vuexP()]
})
